<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基层AI辅助诊断系统 - 病历录入</title>
    <!-- 引入Element Plus的样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
    <!-- 引入Vue 3 -->
    <script src="https://unpkg.com/vue@3"></script>
    <!-- 引入Element Plus组件库 -->
    <script src="https://unpkg.com/element-plus"></script>
    <!-- 引入中文语言包 -->
    <script src="https://unpkg.com/element-plus/dist/locale/zh-cn.min.js"></script>
    <style>
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
            background: #FFFFFF;
            color: var(--text-primary);
            line-height: 1.5;
            font-size: 14px;
            margin: 0;
        }

        /* 色彩系统 - 基于HIS系统现代极简风设计规范 */
        :root {
            /* 主色调 */
            --primary: #0F6CBD;
            --primary-light: #D0E7FF;
            --primary-dark: #0A4F8D;
            
            /* 辅助色 */
            --success: #0F8A5F;
            --warning: #F59337;
            --error: #D13438;
            --info: #0078D4;
            
            /* 中性色 - 文字 */
            --text-primary: #1A1A1A;
            --text-secondary: #4D4D4D;
            --text-tertiary: #767676;
            --text-disabled: #A6A6A6;
            
            /* 中性色 - 边框与分割线 */
            --border-strong: #CCCCCC;
            --border-normal: #E0E0E0;
            --border-light: #F0F0F0;
            --divider: #F5F5F5;
            
            /* 中性色 - 背景 */
            --bg-primary: #FFFFFF;
            --bg-secondary: #F9F9F9;
            --bg-card: #FFFFFF;
            --bg-disabled: #F5F5F5;
            
            /* 医疗专业色 */
            --medical-critical: #B91C1C;
            --medical-abnormal: #F59E0B;
            --medical-normal: #10B981;
            --medical-pending: #3B82F6;
            --medical-completed: #9CA3AF;
            
            /* 间距系统 */
            --spacing-2: 2px;
            --spacing-4: 4px;
            --spacing-8: 8px;
            --spacing-12: 12px;
            --spacing-16: 16px;
            --spacing-24: 24px;
            --spacing-32: 32px;
            --spacing-40: 40px;
            --spacing-48: 48px;
            
            /* 字体大小 */
            --font-page-title: 20px;
            --font-card-title: 16px;
            --font-table-title: 14px;
            --font-body: 14px;
            --font-table: 13px;
            --font-small: 12px;
            
            /* 行高 */
            --line-height-title: 1.4;
            --line-height-body: 1.5;
            --line-height-table: 1.2;
            --line-height-form: 1.4;
            
            /* 圆角 */
            --radius-small: 2px;
            --radius-medium: 4px;
            
            /* 动画时间 */
            --transition-fast: 150ms;
            --transition-normal: 200ms;
            --transition-slow: 300ms;
            
            /* 导航统一宽度（确保标题、指示器、下拉弹窗同轴对齐）*/
            --nav-item-width: 140px;
        }

        /* 基础样式 */
        .btn {
            padding: var(--spacing-8) var(--spacing-16);
            border-radius: var(--radius-small);
            font-size: var(--font-body);
            font-weight: 500;
            cursor: pointer;
            border: none;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: all var(--transition-normal);
            gap: var(--spacing-8);
            height: 32px;
            line-height: 1;
        }
        
        .btn-primary {
            background-color: var(--primary);
            color: white;
        }
        
        .btn-primary:hover {
            background-color: var(--primary-dark);
        }
        
        .btn-default {
            background-color: var(--bg-primary);
            color: var(--text-secondary);
            border: 1px solid var(--border-normal);
        }
        
        .btn-default:hover {
            background-color: var(--bg-secondary);
        }
        
        .form-label {
            display: block;
            margin-bottom: var(--spacing-8);
            font-weight: 500;
            color: var(--text-secondary);
            font-size: var(--font-body);
        }
        
        .label-hint {
            font-weight: normal;
            color: var(--text-tertiary);
            font-size: var(--font-small);
            margin-left: var(--spacing-4);
        }
        
        .form-control {
            width: 100%;
            padding: var(--spacing-8) var(--spacing-12);
            border: 1px solid var(--border-normal);
            border-radius: var(--radius-small);
            font-size: var(--font-body);
            color: var(--text-primary);
            transition: border-color var(--transition-normal);
            height: 32px;
        }
        
        .form-control:focus {
            border-color: var(--primary);
            outline: none;
            box-shadow: 0 0 0 2px rgba(15, 108, 189, 0.2);
        }
        
        textarea.form-control {
            min-height: 80px;
            height: auto;
            resize: vertical;
            line-height: var(--line-height-body);
        }
        
        /* 必填字段标记 */
        .required::after {
            content: '*';
            color: var(--error);
            margin-left: 4px;
        }

        /* 布局容器 */
        .container {
            width: 100%;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            background-color: var(--bg-primary);
        }

        /* 顶部导航栏 - 使用Element Plus样式覆盖 */
        .header {
            height: 60px;
            background-color: var(--bg-primary);
            border-bottom: 1px solid var(--border-normal);
            display: flex;
            align-items: center;
            padding: 0 var(--spacing-24);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            position: relative;
            z-index: 100;
        }

        .header-spacer {
            width: 200px;
            flex-shrink: 0;
        }

        #app-nav {
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            z-index: 10;
            width: calc(100% - 400px); /* 两侧各200px 对称留白 */
            display: flex;
            justify-content: center;
        }
        
        /* Element Plus菜单样式覆盖 */
        .el-menu {
            border: none !important;
            background-color: transparent !important;
        }
        
        .el-menu--horizontal > .el-menu-item,
        .el-menu--horizontal > .el-sub-menu .el-sub-menu__title {
            height: 60px;
            line-height: 60px;
            color: var(--text-secondary);
            font-weight: 500;
            font-size: var(--font-body);
            padding: 0; /* 菜单项承担统一宽度，确保几何中心对齐 */
            width: var(--nav-item-width);
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }

        /* 为有下拉的标题预留规则（改为伪元素放置箭头，与文字并排） */
        .el-menu--horizontal > .el-sub-menu .el-sub-menu__title {
            padding-right: 0; /* 由伪元素与margin控制文字与箭头间距 */
            box-sizing: border-box;
        }

        /* 完全隐藏内置箭头，改用背景图实现，彻底规避文字重叠 */
        .el-sub-menu__icon-arrow { display: none !important; }

        /* 使用伪元素与文字并排放置箭头，统一与参考页一致：箭头16px，间距8px */
        .el-menu--horizontal > .el-sub-menu .el-sub-menu__title::after {
            content: '';
            display: inline-block;
            width: 16px;
            height: 16px;
            margin-left: 8px; /* 与文字保持8px间距 */
            background-repeat: no-repeat;
            background-position: center;
            background-size: 16px 16px; /* 统一箭头尺寸为16px */
            /* 默认灰色向下箭头 */
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23767676' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
        }

        .el-sub-menu:hover > .el-sub-menu__title::after,
        .el-sub-menu.is-active > .el-sub-menu__title::after {
            /* 悬停/激活：主色向下箭头 */
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230F6CBD' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
        }

        .el-sub-menu.is-opened > .el-sub-menu__title::after {
            /* 展开：主色向上箭头 */
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230F6CBD' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 15 12 9 18 15'/></svg>");
        }
        
        .el-menu--horizontal > .el-menu-item.is-active,
        .el-menu--horizontal > .el-sub-menu.is-active .el-sub-menu__title {
            color: var(--primary) !important;
            border-bottom: 2px solid var(--primary);
            font-weight: 500;
        }
        
        .el-menu--horizontal > .el-menu-item:not(.is-disabled):hover,
        .el-menu--horizontal > .el-menu-item:not(.is-disabled):focus,
        .el-menu--horizontal > .el-sub-menu:not(.is-disabled):hover .el-sub-menu__title {
            color: var(--primary);
            background-color: transparent;
        }
        
        /* 下拉菜单样式覆盖 */
        .el-menu--popup {
            width: var(--nav-item-width) !important; /* 与菜单项宽度一致 */
            min-width: var(--nav-item-width) !important;
            max-width: var(--nav-item-width) !important;
            border-radius: var(--radius-small);
            padding: 4px 0;
            border: 1px solid var(--border-light);
            border-top: 2px solid var(--primary); /* 添加主色调顶部边框，增强连贯性 */
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* 减轻阴影效果，降低视觉上的分离感 */
            text-align: center !important; /* 与导航项居中保持一致 */
        }
        
        .el-menu--popup .el-menu-item {
            height: 36px;
            line-height: 36px;
            padding: 0 !important; /* 与导航项宽度对齐 */
            color: var(--text-secondary);
            white-space: nowrap; /* 防止文本换行 */
            text-align: center; /* 文本居中 */
            width: var(--nav-item-width) !important; /* 确保菜单项宽度一致 */
            box-sizing: border-box; /* 确保宽度计算包含内边距和边框 */
            overflow: hidden; /* 隐藏溢出内容 */
            text-overflow: ellipsis; /* 文本溢出显示省略号 */
            display: flex !important; /* 使用flex保证真正居中 */
            justify-content: center !important;
            align-items: center !important;
            font-size: var(--font-body);
        }
        
        .el-menu--popup .el-menu-item:hover {
            background-color: var(--bg-secondary);
            color: var(--primary);
        }

        .user-section {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: var(--spacing-8);
            width: 200px; /* 与左侧spacer对称 */
            cursor: pointer;
            padding: 8px 12px;
            border-radius: var(--radius-small);
            transition: background-color var(--transition-fast), color var(--transition-fast);
            color: var(--text-secondary);
            margin-left: auto; /* 紧贴右边界 */
        }

        .user-section:hover {
            background-color: var(--bg-secondary);
        }

        .user-name {
            font-weight: 500;
            font-size: var(--font-body);
        }

        .user-arrow {
            color: var(--text-tertiary);
            transition: color var(--transition-normal);
        }

        .user-section:hover .user-arrow {
            color: var(--primary);
        }

        /* 用户下拉弹窗 */
        .user-dropdown {
            position: absolute;
            top: 60px; /* 紧贴头部底部 */
            right: var(--spacing-24);
            width: 160px;
            background: var(--bg-primary);
            border: 1px solid var(--border-light);
            border-radius: var(--radius-small);
            box-shadow: 0 4px 12px rgba(0,0,0,0.08);
            display: none;
            z-index: 200;
            overflow: hidden;
        }

        .user-dropdown .item {
            padding: 10px 12px;
            color: var(--text-secondary);
            font-size: var(--font-body);
            cursor: pointer;
            white-space: nowrap;
        }

        .user-dropdown .item:hover {
            background-color: var(--bg-secondary);
            color: var(--primary);
        }
        
        /* 主要内容区域样式 */
        .main-content {
            padding: var(--spacing-24);
            flex: 1;
            background-color: var(--bg-primary);
            width: 100%;
        }
        
        /* 内容头部样式 */
        .content-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: var(--spacing-24);
        }
        
        .page-title {
            font-size: var(--font-page-title);
            font-weight: 600;
            color: var(--text-primary);
            line-height: var(--line-height-title);
        }
        
        /* 病历内容区域样式 */
        .medical-record-container {
            display: flex;
            flex-direction: column;
            gap: var(--spacing-24);
        }
        
        .section-card {
            background-color: var(--bg-card);
            border-radius: var(--radius-small);
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
            border: 1px solid var(--border-light);
            overflow: hidden;
        }
        
        .card-header {
            padding: var(--spacing-16);
            border-bottom: 1px solid var(--border-light);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: var(--bg-secondary);
            min-height: 56px;
            transition: background-color var(--transition-fast);
        }

        .card-header.clickable {
            cursor: pointer;
            user-select: none;
        }

        .card-header.clickable:hover {
            background-color: var(--bg-card);
        }

        .card-header.clickable.expanded {
            border-bottom-color: var(--border-normal);
        }
        
        .card-title {
            font-size: var(--font-card-title);
            font-weight: 600;
            color: var(--text-primary);
            line-height: var(--line-height-title);
        }
        
        .card-body {
            padding: var(--spacing-16);
        }
        
        .btn-icon,
        .toggle-icon {
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: transparent;
            border: none;
            border-radius: var(--radius-small);
            color: var(--text-tertiary);
            cursor: pointer;
            transition: background-color var(--transition-fast);
        }
        
        .btn-icon:hover {
            background-color: rgba(0, 0, 0, 0.05);
            color: var(--text-secondary);
        }
        
        .btn-icon svg {
            transition: transform var(--transition-normal);
        }
        
        .toggle-icon svg {
            transition: transform var(--transition-normal);
        }
        
        .toggle-icon.expanded svg {
            transform: rotate(180deg);
        }
        
        /* 折叠面板样式 */
        .collapsible-section {
            margin-bottom: var(--spacing-16);
            border: 1px solid var(--border-light);
            border-radius: var(--radius-small);
            overflow: hidden;
        }
        
        .collapsible-header {
            padding: var(--spacing-12) var(--spacing-16);
            background-color: var(--bg-secondary);
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: center;
            user-select: none;
        }
        
        .collapsible-title {
            font-weight: 500;
            color: var(--text-secondary);
            font-size: var(--font-body);
        }
        
        .collapsible-icon {
            transition: transform var(--transition-normal);
            color: var(--text-tertiary);
        }
        
        .collapsible-content {
            padding: var(--spacing-16);
            border-top: 1px solid var(--border-light);
            display: none;
        }
        
        .collapsible-section.expanded .collapsible-icon {
            transform: rotate(180deg);
        }
        
        .collapsible-section.expanded .collapsible-content {
            display: block;
        }
        
        /* 表单样式 */
        .form-group {
            margin-bottom: var(--spacing-16);
        }
        
        .form-row {
            display: flex;
            gap: var(--spacing-16);
            margin-bottom: var(--spacing-16);
            flex-wrap: wrap;
        }
        
        .form-item {
            flex: 1;
            min-width: 180px;
            margin-bottom: var(--spacing-16);
        }
        
        .input-with-dropdown {
            position: relative;
            width: 100%;
        }
        
        .input-with-dropdown .input-suffix {
            position: absolute;
            right: 8px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-tertiary);
            pointer-events: none;
        }
        
        .input-with-unit {
            width: 100%;
        }
        
        .input-unit-wrapper {
            position: relative;
            display: flex;
            align-items: center;
        }
        
        .input-unit {
            position: absolute;
            right: 8px;
            color: var(--text-tertiary);
            font-size: var(--font-small);
            pointer-events: none;
        }
        
        .template-select-wrapper {
            position: relative;
            width: 100%;
            display: block;
        }
        
        .template-select {
            width: 100%;
            min-width: 250px;
            padding: var(--spacing-8) var(--spacing-12);
            appearance: auto; /* 恢复浏览器默认的下拉箭头 */
            -webkit-appearance: auto;
            -moz-appearance: auto;
            background-color: var(--bg-primary);
            border: 1px solid var(--border-normal);
            border-radius: var(--radius-medium);
            font-size: var(--font-body);
            color: var(--text-primary);
            box-sizing: border-box;
            height: 38px; /* 明确设置高度 */
            line-height: 22px; /* 设置行高 */
        }
        
        /* 确保下拉选项能够完全显示文本 */
        select.template-select option {
            padding: var(--spacing-8);
            white-space: normal;
        }
        
        /* 修复表单行的样式 */
        .form-row {
            display: flex;
            flex-wrap: wrap;
            margin: 0 -8px;
            width: 100%;
        }
        
        .form-item {
            padding: 0 8px;
            margin-bottom: var(--spacing-16);
            min-width: 200px;
            flex: 1;
        }
        
        .form-label {
            display: block;
            margin-bottom: var(--spacing-8);
            font-weight: 500;
            color: var(--text-secondary);
        }
        
        .form-control {
            width: 100%;
            padding: var(--spacing-8) var(--spacing-12);
            border: 1px solid var(--border-normal);
            border-radius: 2px;
            font-size: 14px;
            color: var(--text-primary);
            transition: border-color 0.2s;
        }
        
        .form-control:focus {
            border-color: var(--primary);
            outline: none;
            box-shadow: 0 0 0 2px rgba(15, 108, 189, 0.2);
        }
        
        textarea.form-control {
            min-height: 80px;
            resize: vertical;
        }
        
        /* 折叠面板样式 */
        .collapsible-section {
            margin-bottom: var(--spacing-16);
        }
        
        .collapsible-header {
            padding: var(--spacing-12) var(--spacing-16);
            background-color: var(--bg-secondary);
            border: 1px solid var(--border-light);
            border-radius: 2px;
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .collapsible-title {
            font-weight: 500;
            color: var(--text-secondary);
        }
        
        .collapsible-icon {
            transition: transform 0.3s;
        }
        
        .collapsible-content {
            padding: var(--spacing-16);
            border: 1px solid var(--border-light);
            border-top: none;
            border-radius: 0 0 2px 2px;
            display: none;
        }
        
        .collapsible-section.expanded .collapsible-icon {
            transform: rotate(180deg);
        }
        
        .collapsible-section.expanded .collapsible-content {
            display: block;
        }
        
        /* 按钮样式 */
        .btn {
            padding: var(--spacing-8) var(--spacing-16);
            border-radius: 2px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            border: none;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
            gap: var(--spacing-8);
            height: 32px;
            line-height: 1;
        }
        
        .btn .icon {
            flex-shrink: 0;
        }
        
        .btn-primary {
            background-color: var(--primary);
            color: white;
        }
        
        .btn-primary:hover {
            background-color: var(--primary-dark);
        }
        
        .btn-default {
            background-color: var(--bg-primary);
            color: var(--text-secondary);
            border: 1px solid var(--border-normal);
        }
        
        .btn-default:hover {
            background-color: var(--bg-secondary);
        }
        
        /* 底部操作栏 */
        .footer-actions {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: var(--spacing-16) var(--spacing-24);
            margin-top: var(--spacing-24);
            border-top: 1px solid var(--border-light);
            background-color: var(--bg-secondary);
            border-radius: 0 0 var(--radius-small) var(--radius-small);
            position: sticky;
            bottom: 0;
            z-index: 10;
        }
        
        .action-buttons {
            display: flex;
            gap: var(--spacing-16);
        }
        
        .fee-summary {
            display: flex;
            align-items: baseline;
            gap: var(--spacing-4);
        }
        
        .fee-label {
            font-size: var(--font-body);
            color: var(--text-secondary);
            font-weight: 500;
        }
        
        .fee-amount {
            font-size: 20px;
            color: var(--primary);
            font-weight: 600;
        }
        
        .fee-unit {
            font-size: var(--font-body);
            color: var(--text-secondary);
        }
        
        .fee-hint {
            font-size: var(--font-small);
            color: var(--text-tertiary);
            margin-left: var(--spacing-8);
        }
        
        
        
        /* 表格样式 */
        .table-container {
            overflow-x: auto;
            margin-bottom: var(--spacing-16);
            border: 1px solid var(--border-normal);
            border-radius: var(--radius-small);
        }
        
        .data-table {
            width: 100%;
            border-collapse: collapse;
        }
        
        .data-table th {
            background-color: var(--bg-secondary);
            padding: var(--spacing-8) var(--spacing-16);
            text-align: left;
            font-weight: 600;
            color: var(--text-secondary);
            border-bottom: 1px solid var(--border-normal);
            height: 32px;
            font-size: var(--font-table-title);
        }
        
        .data-table td {
            padding: var(--spacing-8) var(--spacing-16);
            border-bottom: 1px solid var(--border-light);
            color: var(--text-secondary);
            height: 32px;
            vertical-align: middle;
            font-size: var(--font-table);
        }
        
        .data-table tr:hover {
            background-color: var(--bg-secondary);
        }
        
        .empty-table-message {
            text-align: center;
            color: var(--text-tertiary);
            padding: var(--spacing-16);
            font-style: italic;
        }
        
        .prescription-header {
            margin-bottom: var(--spacing-16);
            display: flex;
            justify-content: flex-end; /* 右对齐添加药品按钮 */
            align-items: center;
        }
        
        /* 弹窗样式 */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transition: opacity var(--transition-normal) ease-out;
            backdrop-filter: blur(2px);
        }
        
        .modal-overlay.active {
            opacity: 1;
            visibility: visible;
        }
        
        .modal {
            background-color: var(--bg-primary);
            border-radius: var(--radius-small);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            width: 100%;
            max-width: 800px;
            max-height: 85vh;
            display: flex;
            flex-direction: column;
            transform: scale(0.95);
            transition: transform var(--transition-normal) ease-out;
            border: 1px solid var(--border-light);
        }
        
        .modal-overlay.active .modal {
            transform: scale(1);
        }
        
        .modal-header {
            padding: var(--spacing-16) var(--spacing-24);
            border-bottom: 1px solid var(--border-light);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: var(--bg-primary);
        }
        
        .modal-title {
            font-size: var(--font-card-title);
            font-weight: 600;
            color: var(--text-primary);
            line-height: var(--line-height-title);
        }
        
        .modal-close {
            background: none;
            border: none;
            cursor: pointer;
            color: var(--text-tertiary);
            font-size: 20px;
            padding: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: var(--radius-small);
            transition: background-color var(--transition-fast);
        }
        
        .modal-close:hover {
            background-color: var(--bg-secondary);
        }
        
        .modal-body {
            padding: var(--spacing-24);
            overflow-y: auto;
            flex: 1;
        }
        
        .modal-footer {
            padding: var(--spacing-16) var(--spacing-24);
            border-top: 1px solid var(--border-light);
            display: flex;
            justify-content: flex-end;
            gap: var(--spacing-16);
            background-color: var(--bg-primary);
        }
        
        .modal-section {
            margin-bottom: var(--spacing-24);
            padding-bottom: var(--spacing-16);
            border-bottom: 1px solid var(--border-light);
        }
        
        .modal-section:last-child {
            margin-bottom: 0;
            padding-bottom: 0;
            border-bottom: none;
        }
        
        .modal-section-title {
            font-weight: 500;
            color: var(--text-secondary);
            margin-bottom: var(--spacing-8);
            font-size: var(--font-body);
        }
        
        /* AI诊断结果样式 */
        .ai-result-box {
            display: flex;
            flex-direction: column;
            gap: var(--spacing-12);
            margin-top: var(--spacing-12);
        }
        
        .ai-result-item {
            display: flex;
            align-items: center;
            gap: var(--spacing-16);
            padding: var(--spacing-12);
            background-color: var(--bg-secondary);
            border-radius: var(--radius-small);
            border-left: 3px solid var(--primary);
        }
        
        .ai-result-probability {
            font-size: 18px;
            font-weight: 600;
            color: var(--primary);
            min-width: 50px;
        }
        
        .ai-result-content {
            font-size: var(--font-body);
            color: var(--text-secondary);
        }
        
        /* AI诊断依据样式 */
        .ai-basis-box {
            display: flex;
            flex-direction: column;
            gap: var(--spacing-12);
            margin-top: var(--spacing-12);
        }
        
        .ai-basis-item {
            padding: var(--spacing-12);
            background-color: var(--bg-secondary);
            border-radius: var(--radius-small);
        }
        
        .ai-basis-label {
            font-weight: 500;
            color: var(--text-secondary);
            margin-bottom: var(--spacing-4);
        }
        
        .ai-basis-content {
            color: var(--text-secondary);
            line-height: var(--line-height-body);
        }
        
        /* AI医嘱样式 */
        .ai-advice-box {
            padding: var(--spacing-12);
            background-color: var(--bg-secondary);
            border-radius: var(--radius-small);
            margin-top: var(--spacing-12);
        }
        
        .ai-advice-item {
            padding: var(--spacing-4) 0;
            color: var(--text-secondary);
            line-height: var(--line-height-body);
        }
        
        /* AI医疗安全检查样式 */
        .progress-bar-container {
            position: relative;
            height: 8px;
            background-color: var(--border-light);
            border-radius: 4px;
            overflow: hidden;
            margin: var(--spacing-12) 0;
        }
        
        .progress-bar {
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            background-color: var(--primary);
            border-radius: 4px;
        }
        
        .progress-percentage {
            text-align: right;
            font-size: var(--font-small);
            color: var(--text-tertiary);
            margin-top: var(--spacing-4);
        }
        
        .safety-summary {
            display: flex;
            gap: var(--spacing-16);
            margin-top: var(--spacing-12);
        }
        
        .safety-summary-item {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: var(--spacing-12);
            border-radius: var(--radius-small);
            background-color: var(--bg-secondary);
        }
        
        .safety-summary-count {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: var(--spacing-4);
        }
        
        .safety-summary-label {
            font-size: var(--font-small);
            color: var(--text-secondary);
        }
        
        .safety-critical {
            border-left: 3px solid var(--error);
        }
        
        .safety-critical .safety-summary-count {
            color: var(--error);
        }
        
        .safety-warning {
            border-left: 3px solid var(--warning);
        }
        
        .safety-warning .safety-summary-count {
            color: var(--warning);
        }
        
        .safety-info {
            border-left: 3px solid var(--info);
        }
        
        .safety-info .safety-summary-count {
            color: var(--info);
        }
        
        .safety-check-list {
            display: flex;
            flex-direction: column;
            gap: var(--spacing-12);
            margin-top: var(--spacing-12);
        }
        
        .safety-check-item {
            display: flex;
            flex-direction: column;
            gap: var(--spacing-8);
            padding: var(--spacing-12);
            border-radius: var(--radius-small);
            background-color: var(--bg-secondary);
        }
        
        .safety-check-item.critical {
            border-left: 3px solid var(--error);
        }
        
        .safety-check-item.warning {
            border-left: 3px solid var(--warning);
        }
        
        .safety-check-item.info {
            border-left: 3px solid var(--info);
        }
        
        .safety-check-content {
            display: flex;
            gap: var(--spacing-8);
        }
        
        .safety-check-icon {
            font-size: 16px;
            line-height: 1.4;
        }
        
        .safety-check-text {
            flex: 1;
        }
        
        .safety-check-title {
            font-weight: 500;
            color: var(--text-secondary);
            margin-bottom: var(--spacing-4);
        }
        
        .safety-check-suggestion {
            color: var(--text-tertiary);
            font-size: var(--font-small);
            line-height: var(--line-height-body);
        }
        
        .safety-check-actions {
            display: flex;
            gap: var(--spacing-8);
            margin-top: var(--spacing-8);
            justify-content: flex-end;
        }
        
        .btn-sm {
            padding: var(--spacing-4) var(--spacing-8);
            font-size: var(--font-small);
            height: 24px;
        }
        
        /* 图片上传区域 */
        .image-upload-area {
            display: flex;
            gap: var(--spacing-16);
            flex-wrap: wrap;
            margin-bottom: var(--spacing-16);
        }
        
        .image-upload-box {
            width: 120px;
            height: 120px;
            border: 1px dashed var(--border-normal);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all var(--transition-normal);
            border-radius: var(--radius-small);
            color: var(--text-tertiary);
        }
        
        .image-upload-box:hover {
            border-color: var(--primary);
            background-color: rgba(15, 108, 189, 0.05);
            color: var(--primary);
        }
        
        .image-upload-box .icon {
            margin-bottom: var(--spacing-8);
            color: inherit;
        }
        
        .image-upload-box .text {
            font-size: var(--font-small);
            text-align: center;
            color: inherit;
        }
        
        .image-preview {
            width: 120px;
            height: 120px;
            border: 1px solid var(--border-light);
            position: relative;
            border-radius: var(--radius-small);
            overflow: hidden;
        }
        
        .image-preview img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        .image-delete {
            position: absolute;
            top: 8px;
            right: 8px;
            width: 24px;
            height: 24px;
            background-color: rgba(0, 0, 0, 0.6);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            cursor: pointer;
            opacity: 0;
            transition: opacity var(--transition-fast);
        }
        
        .image-preview:hover .image-delete {
            opacity: 1;
        }
        
        .image-hint {
            margin-top: var(--spacing-8);
            color: var(--text-tertiary);
            font-size: var(--font-small);
        }
        
        .image-upload-hint {
            margin-bottom: var(--spacing-16);
            color: var(--text-tertiary);
            font-size: var(--font-small);
            background-color: var(--bg-secondary);
            padding: var(--spacing-8) var(--spacing-12);
            border-radius: var(--radius-small);
            border-left: 3px solid var(--primary);
        }
        
        .ai-diagnosis-btn-container {
            margin: var(--spacing-24) 0;
            display: flex;
            justify-content: center;
        }
        
        .ai-diagnosis-btn {
            padding: var(--spacing-12) var(--spacing-24);
            font-size: var(--font-card-title);
            height: 48px;
            min-width: 200px;
            display: flex;
            align-items: center;
            gap: var(--spacing-8);
        }
        
        .ai-diagnosis-btn svg {
            flex-shrink: 0;
        }
        
        /* 响应式样式 */
        @media (max-width: 768px) {
            .header {
                flex-wrap: wrap;
                padding: var(--spacing-12) var(--spacing-16);
                height: auto;
            }
            
            .logo-section {
                width: 100%;
                justify-content: center;
                margin-bottom: 8px;
            }
            
            .user-section {
                width: 100%;
                justify-content: center;
                order: 3;
                margin-top: 8px;
            }
            
            #app-nav {
                position: relative;
                left: 0;
                transform: none;
                width: 100%;
                order: 3;
                margin-top: var(--spacing-8);
            }
            
            /* Element Plus移动端菜单样式覆盖 */
            .el-menu--collapse {
                width: 100%;
            }
            
            .el-menu--horizontal {
                flex-wrap: wrap;
                width: 100%;
                overflow-x: auto;
                white-space: nowrap;
                -webkit-overflow-scrolling: touch;
                padding-bottom: var(--spacing-4);
                justify-content: center;
            }
            
            .el-menu--horizontal > .el-menu-item,
            .el-menu--horizontal > .el-sub-menu .el-sub-menu__title {
                height: 48px;
                line-height: 48px;
            }
            
            .main-content {
                padding: var(--spacing-16);
            }
            
            .content-header {
                flex-direction: column;
                align-items: flex-start;
                gap: var(--spacing-16);
            }
            
            .form-row {
                flex-direction: column;
            }
            
            .form-item {
                width: 100%;
            }
            
            .modal {
                width: 95%;
                max-width: none;
            }
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="container">
            <!-- 顶部导航栏 - 使用Element Plus组件 -->
            <header class="header">
                <div class="header-spacer"></div>
                <div id="app-nav">
                    <el-menu 
                        :default-active="activeIndex" 
                        class="el-menu-demo" 
                        mode="horizontal" 
                        @select="handleSelect"
                        :ellipsis="false"
                        :popper-offset="0"
                        popper-class="custom-dropdown">
                        <el-menu-item index="1">开始问诊</el-menu-item>
                        <el-sub-menu index="2" popper-class="custom-dropdown">
                            <template #title>病历管理</template>
                            <el-menu-item index="2-1">病历查询</el-menu-item>
                            <el-menu-item index="2-2">病历模板</el-menu-item>
                            <el-menu-item index="2-3">个人药品</el-menu-item>
                        </el-sub-menu>
                        <el-menu-item index="3">患者管理</el-menu-item>
                        <el-sub-menu index="4" popper-class="custom-dropdown">
                            <template #title>数据统计</template>
                            <el-menu-item index="4-1">诊断统计</el-menu-item>
                            <el-menu-item index="4-2">宏观统计</el-menu-item>
                        </el-sub-menu>
                        <el-menu-item index="5">医学知识</el-menu-item>
                        <el-sub-menu index="6" popper-class="custom-dropdown">
                            <template #title>基础数据</template>
                            <el-menu-item index="6-1">药品管理</el-menu-item>
                        </el-sub-menu>
                        <el-sub-menu index="7" popper-class="custom-dropdown">
                            <template #title>消息通知</template>
                            <el-menu-item index="7-1">通知查看</el-menu-item>
                            <el-menu-item index="7-2">通知发布</el-menu-item>
                        </el-sub-menu>
                        <el-sub-menu index="8" popper-class="custom-dropdown">
                            <template #title>用户管理</template>
                            <el-menu-item index="8-1">用户管理</el-menu-item>
                            <el-menu-item index="8-2">角色管理</el-menu-item>
                        </el-sub-menu>
                    </el-menu>
                </div>
                <div class="user-section" id="userSection">
                    <span class="user-name">张医生</span>
                    <svg class="user-arrow" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polyline points="6 9 12 15 18 9"></polyline>
                    </svg>
                </div>
                <div class="user-dropdown" id="userDropdown">
                    <div class="item">个人中心</div>
                    <div class="item">退出登录</div>
                </div>
            </header>
            
            <!-- 主要内容区域 -->
            <div class="main-content">
                <div class="content-header">
                    <h2 class="page-title">病历录入</h2>
                </div>
                
                <div class="medical-record-container">
                    <!-- 患者信息区域 -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title">患者信息区域</div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <div class="form-row">
                                    <div class="form-item">
                                        <label for="patientName" class="form-label required">姓名</label>
                                        <div class="input-with-dropdown">
                                            <input type="text" id="patientName" class="form-control" placeholder="请输入患者姓名">
                                            <span class="input-suffix">
                                                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                                    <polyline points="6 9 12 15 18 9"></polyline>
                                                </svg>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="form-item">
                                        <label for="gender" class="form-label required">性别</label>
                                        <select id="gender" class="form-control">
                                            <option value="">请选择</option>
                                            <option value="male">男</option>
                                            <option value="female">女</option>
                                        </select>
                                    </div>
                                    <div class="form-item">
                                        <label for="age" class="form-label required">年龄</label>
                                        <input type="number" id="age" class="form-control" placeholder="请输入">
                                    </div>
                                    <div class="form-item">
                                        <label for="idCard" class="form-label">身份证</label>
                                        <input type="text" id="idCard" class="form-control" placeholder="请输入">
                                    </div>
                                    <div class="form-item">
                                        <label for="phone" class="form-label required">电话</label>
                                        <input type="tel" id="phone" class="form-control" placeholder="请输入">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 病历模板选择区域 -->
                    <div class="section-card">
                        <div class="card-body">
                            <div class="form-group">
                                <div class="form-row">
                                    <div class="form-item" style="width: 100%;">
                                        <div class="template-select-wrapper">
                                            <select id="medicalTemplate" class="template-select">
                                            <option value="">选择病历模板</option>
                                            <option value="template1">常见感冒模板</option>
                                            <option value="template2">消化系统疾病模板</option>
                                            <option value="template3">呼吸系统疾病模板</option>
                                            <option value="template4">皮肤科疾病模板</option>
                                            <option value="template5">儿科常见疾病模板</option>
                                        </select>
                                        </div>
                                    </div>
                                </div>
                                    </div>
                                </div>
                            </div>
                            
                            
                    <!-- 主诉区域 -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title required">主诉</div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <textarea id="chiefComplaint" class="form-control" placeholder="请输入患者的主要症状和不适"></textarea>
                            </div>
                        </div>
                            </div>
                            
                    <!-- 病史区域 -->
                    <div class="section-card">
                        <div class="card-header clickable" id="historyHeader">
                            <div class="card-title">病史</div>
                            <button class="btn-icon toggle-icon">
                                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                    <polyline points="6 9 12 15 18 9"></polyline>
                                </svg>
                            </button>
                        </div>
                        <div class="card-body collapsible-content" id="historyContent" style="display: none;">
                            <div class="form-group">
                                <div class="form-row">
                                    <div class="form-item">
                                        <label for="presentIllness" class="form-label">现病史</label>
                                        <textarea id="presentIllness" class="form-control" placeholder="请输入现病史"></textarea>
                                    </div>
                                    <div class="form-item">
                                        <label for="allergyHistory" class="form-label">过敏史</label>
                                        <textarea id="allergyHistory" class="form-control" placeholder="请输入过敏史"></textarea>
                                    </div>
                                    </div>
                                <div class="form-row">
                                    <div class="form-item">
                                        <label for="pastHistory" class="form-label">既往史</label>
                                        <textarea id="pastHistory" class="form-control" placeholder="请输入既往史"></textarea>
                                    </div>
                                    <div class="form-item">
                                        <label for="personalHistory" class="form-label">个人史</label>
                                        <textarea id="personalHistory" class="form-control" placeholder="请输入个人史"></textarea>
                                    </div>
                                </div>
                                <div class="form-row">
                                    <div class="form-item">
                                        <label for="familyHistory" class="form-label">家族史</label>
                                        <textarea id="familyHistory" class="form-control" placeholder="请输入家族史"></textarea>
                                    </div>
                                </div>
                                    </div>
                                </div>
                            </div>
                            
                    <!-- 体格检查区域 -->
                    <div class="section-card">
                        <div class="card-header clickable" id="physicalExamHeader">
                            <div class="card-title">体格检查</div>
                            <button class="btn-icon toggle-icon">
                                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                    <polyline points="6 9 12 15 18 9"></polyline>
                                </svg>
                            </button>
                        </div>
                        <div class="card-body collapsible-content" id="physicalExamContent" style="display: none;">
                            <div class="form-group">
                                <label class="form-label">生命体征</label>
                                <div class="form-row">
                                    <div class="form-item">
                                        <div class="input-with-unit">
                                            <label for="temperature" class="form-label">体温</label>
                                            <div class="input-unit-wrapper">
                                                <input type="number" id="temperature" class="form-control" placeholder="请输入" step="0.1">
                                                <span class="input-unit">℃</span>
                                        </div>
                                    </div>
                                        </div>
                                    <div class="form-item">
                                        <div class="input-with-unit">
                                            <label for="pulse" class="form-label">脉搏</label>
                                            <div class="input-unit-wrapper">
                                                <input type="number" id="pulse" class="form-control" placeholder="请输入">
                                                <span class="input-unit">次/分</span>
                                    </div>
                                        </div>
                                    </div>
                                    <div class="form-item">
                                        <div class="input-with-unit">
                                            <label for="respiration" class="form-label">呼吸</label>
                                            <div class="input-unit-wrapper">
                                                <input type="number" id="respiration" class="form-control" placeholder="请输入">
                                                <span class="input-unit">次/分</span>
                                        </div>
                                        </div>
                                    </div>
                                    <div class="form-item">
                                        <div class="input-with-unit">
                                            <label for="bloodPressure" class="form-label">血压</label>
                                            <div class="input-unit-wrapper">
                                                <input type="text" id="bloodPressure" class="form-control" placeholder="请输入">
                                                <span class="input-unit">mmHg</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="generalCondition" class="form-label">一般状况</label>
                                <textarea id="generalCondition" class="form-control" placeholder="请描述患者一般状况"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="specialExam" class="form-label">专科检查</label>
                                <textarea id="specialExam" class="form-control" placeholder="请描述专科检查结果"></textarea>
                                    </div>
                                </div>
                            </div>
                            
                    <!-- 图像采集区域 -->
                    <div class="section-card">
                        <div class="card-header clickable" id="imageCaptureHeader">
                            <div class="card-title">图像采集</div>
                            <button class="btn-icon toggle-icon">
                                        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                            <polyline points="6 9 12 15 18 9"></polyline>
                                        </svg>
                            </button>
                                    </div>
                        <div class="card-body collapsible-content" id="imageCaptureContent" style="display: none;">
                                    <div class="form-group">
                                <div class="image-upload-hint">提示：请上传清晰的病变部位照片，多角度拍摄可提高诊断准确率</div>
                                <div class="image-upload-area">
                                                <div class="image-upload-box" id="uploadImageBox">
                                        <div class="icon">
                                            <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                                        <path d="M21 19H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h5l2-3h4l2 3h5a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2z"></path>
                                                        <circle cx="12" cy="13" r="4"></circle>
                                                    </svg>
                                        </div>
                                        <div class="text">上传图片<br>(皮肤病变)</div>
                                                    <input type="file" id="imageUpload" style="display: none;" accept="image/*">
                                                </div>
                                                
                                                <!-- 图片预览示例 -->
                                                <div class="image-preview" style="display: none;" id="imagePreview1">
                                                    <img src="#" alt="病变图片预览">
                                                    <div class="image-delete" onclick="deleteImage('imagePreview1')">
                                                        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                                            <line x1="18" y1="6" x2="6" y2="18"></line>
                                                            <line x1="6" y1="6" x2="18" y2="18"></line>
                                                        </svg>
                                                </div>
                                            </div>
                                            
                                    <div class="image-preview" style="display: none;" id="imagePreview2">
                                        <img src="#" alt="病变图片预览">
                                        <div class="image-delete" onclick="deleteImage('imagePreview2')">
                                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                                <line x1="18" y1="6" x2="6" y2="18"></line>
                                                <line x1="6" y1="6" x2="18" y2="18"></line>
                                                    </svg>
                                        </div>
                                    </div>
                                    
                                    <div class="image-preview" style="display: none;" id="imagePreview3">
                                        <img src="#" alt="病变图片预览">
                                        <div class="image-delete" onclick="deleteImage('imagePreview3')">
                                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                                <line x1="18" y1="6" x2="6" y2="18"></line>
                                                <line x1="6" y1="6" x2="18" y2="18"></line>
                                            </svg>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                            
                            <div class="form-group">
                                <label for="imageDescription" class="form-label">图像描述</label>
                                <textarea id="imageDescription" class="form-control" placeholder="请描述病变位置、颜色、大小、形状、持续时间等特征"></textarea>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- AI辅助诊断按钮 -->
                    <div class="ai-diagnosis-btn-container">
                        <button class="btn btn-primary ai-diagnosis-btn" id="aiDiagnosisBtn">
                            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                        <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
                                        <polyline points="22 4 12 14.01 9 11.01"></polyline>
                                    </svg>
                            AI辅助诊断
                                </button>
                            </div>
                            
                    <!-- 诊断区域 -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title required">诊断</div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <label for="diagnosis" class="form-label">诊断结果</label>
                                <textarea id="diagnosis" class="form-control" placeholder="请输入诊断结果"></textarea>
                            </div>
                            
                            <div class="form-group">
                                <label for="diagnosisBasis" class="form-label">诊断依据</label>
                                <textarea id="diagnosisBasis" class="form-control" placeholder="请输入诊断依据"></textarea>
                            </div>
                            
                        </div>
                    </div>
                            
                    <!-- 处方区域 -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title required">处方</div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <div class="prescription-header">
                                    <button class="btn btn-default" id="addMedicineBtn">
                                        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                            <line x1="12" y1="5" x2="12" y2="19"></line>
                                            <line x1="5" y1="12" x2="19" y2="12"></line>
                                        </svg>
                                        添加药品
                                    </button>
                                </div>
                                
                                <div class="table-container">
                                    <table class="data-table">
                                        <thead>
                                            <tr>
                                                <th>药名*</th>
                                                <th>规格*</th>
                                                <th>用法*</th>
                                                <th>用量*</th>
                                                <th>频次*</th>
                                                <th>天数*</th>
                                                <th>单价*</th>
                                                <th>数量*</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="medicineTableBody">
                                            <!-- 药品行将通过JavaScript动态添加 -->
                                            <tr>
                                                <td colspan="9" class="empty-table-message">暂无药品，请点击"添加药品"按钮</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                                </div>
                            </div>
                            
                            <!-- 医嘱区域 -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title">医嘱</div>
                            </div>
                        <div class="card-body">
                            <div class="form-group">
                                <label for="medicalAdvice" class="form-label">医嘱内容</label>
                                <textarea id="medicalAdvice" class="form-control" placeholder="请输入医嘱内容"></textarea>
                            </div>
                        </div>
                            </div>
                            
                    <!-- 医疗安全检查（诊断合理性检查） -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title">医疗安全检查</div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <button class="btn btn-default" id="checkDiagnosisBtn">
                                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                        <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
                                        <polyline points="22 4 12 14.01 9 11.01"></polyline>
                                    </svg>
                                    诊断合理性检查
                                </button>
                                <p class="label-hint">综合病史、体格检查、图像与处方进行AI安全性评估</p>
                            </div>
                        </div>
                    </div>

                    <!-- 费用明细区域 -->
                    <div class="section-card">
                        <div class="card-header">
                            <div class="card-title">费用明细</div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <div class="form-row">
                                    <div class="form-item">
                                        <div class="input-with-unit">
                                            <label for="consultationFee" class="form-label required">问诊费用</label>
                                            <div class="input-unit-wrapper">
                                            <input type="number" id="consultationFee" class="form-control" placeholder="请输入" value="">
                                                <span class="input-unit">元</span>
                                        </div>
                                    </div>
                                        </div>
                                    <div class="form-item">
                                        <div class="input-with-unit">
                                            <label for="medicineFee" class="form-label">
                                                药品费用
                                                <span class="label-hint">(根据处方自动计算)</span>
                                            </label>
                                            <div class="input-unit-wrapper">
                                            <input type="number" id="medicineFee" class="form-control" value="0" readonly>
                                                <span class="input-unit">元</span>
                                            </div>
                                        </div>
                                    </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                        </div>
                    </div>
                </div>
                
                
                
                <!-- 底部操作栏 -->
                <div class="footer-actions">
                    <div class="fee-summary">
                        <span class="fee-label">费用合计:</span>
                        <span class="fee-amount" id="totalFeeDisplay">0</span>
                        <span class="fee-unit">元</span>
                        <span class="fee-hint">(问诊费用 + 药品费用)</span>
                    </div>
                    <div class="action-buttons">
                        <button class="btn btn-default" id="resetBtn">重置</button>
                        <button class="btn btn-primary" id="saveBtn">保存病历</button>
                    </div>
                </div>
            </div>
            
            <!-- AI辅助诊断弹窗 -->
            <div class="modal-overlay" id="aiDiagnosisModal">
                <div class="modal">
                    <div class="modal-header">
                        <h3 class="modal-title">AI诊断结果</h3>
                        <button class="modal-close" id="closeAiDiagnosisModal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <div class="modal-section">
                            <div class="modal-section-title">患者信息</div>
                            <div id="patientInfoInModal">张三（男，35岁）</div>
                        </div>
                        
                        <div class="modal-section">
                            <div class="modal-section-title">AI诊断建议</div>
                            <div class="ai-result-box">
                                <div class="ai-result-item">
                                    <div class="ai-result-probability">85%</div>
                                    <div class="ai-result-content">上呼吸道感染</div>
                                </div>
                                <div class="ai-result-item">
                                    <div class="ai-result-probability">45%</div>
                                    <div class="ai-result-content">急性支气管炎</div>
                                </div>
                                <div class="ai-result-item">
                                    <div class="ai-result-probability">30%</div>
                                    <div class="ai-result-content">过敏性鼻炎</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="modal-section">
                            <div class="modal-section-title">诊断依据</div>
                            <div class="ai-basis-box">
                                <div class="ai-basis-item">
                                    <div class="ai-basis-label">症状分析</div>
                                    <div class="ai-basis-content">患者主诉发热、咳嗽3天，体温38.5℃，伴有咽痛、流涕等症状</div>
                                </div>
                                <div class="ai-basis-item">
                                    <div class="ai-basis-label">体征分析</div>
                                    <div class="ai-basis-content">咽部充血，双侧扁桃体Ⅰ度肿大，未见明显分泌物</div>
                                </div>
                                <div class="ai-basis-item">
                                    <div class="ai-basis-label">辅助检查</div>
                                    <div class="ai-basis-content">血常规示白细胞计数轻度升高，以中性粒细胞为主</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="modal-section">
                            <div class="modal-section-title">推荐处方</div>
                            <div class="table-container">
                                <table class="data-table">
                                    <thead>
                                        <tr>
                                            <th>药名</th>
                                            <th>规格</th>
                                            <th>用法</th>
                                            <th>用量</th>
                                            <th>频次</th>
                                            <th>天数</th>
                                            <th>单价</th>
                                            <th>数量</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>布洛芬</td>
                                            <td>0.2g/片</td>
                                            <td>口服</td>
                                            <td>1片</td>
                                            <td>tid</td>
                                            <td>3天</td>
                                            <td>0.28</td>
                                            <td>9片</td>
                                        </tr>
                                        <tr>
                                            <td>感冒灵</td>
                                            <td>10g/袋</td>
                                            <td>冲服</td>
                                            <td>1袋</td>
                                            <td>tid</td>
                                            <td>3天</td>
                                            <td>2.50</td>
                                            <td>9袋</td>
                                        </tr>
                                        <tr>
                                            <td>板蓝根</td>
                                            <td>10g/袋</td>
                                            <td>冲服</td>
                                            <td>1袋</td>
                                            <td>tid</td>
                                            <td>3天</td>
                                            <td>3.50</td>
                                            <td>9袋</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        
                        <div class="modal-section">
                            <div class="modal-section-title">推荐医嘱</div>
                            <div class="ai-advice-box">
                                <div class="ai-advice-item">1. 多饮水，注意休息</div>
                                <div class="ai-advice-item">2. 避免辛辣刺激食物</div>
                                <div class="ai-advice-item">3. 症状无缓解，3天后复诊</div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" id="adoptDiagnosisBtn">采纳诊断结果</button>
                        <button class="btn btn-default" id="adoptPrescriptionBtn">采纳处方</button>
                        <button class="btn btn-default" id="adoptAdviceBtn">采纳医嘱</button>
                        <button class="btn btn-primary" id="adoptAllBtn">全部采纳</button>
                        <button class="btn btn-default" id="cancelAiDiagnosisBtn">取消</button>
                    </div>
                </div>
            </div>
            
            <!-- AI医疗安全检查弹窗 -->
            <div class="modal-overlay" id="safetyCheckModal">
                <div class="modal">
                    <div class="modal-header">
                        <h3 class="modal-title">AI医疗安全检查</h3>
                        <button class="modal-close" id="closeSafetyCheckModal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <div class="modal-section">
                            <div class="modal-section-title">检查进度</div>
                            <div class="progress-bar-container">
                                <div class="progress-bar" style="width: 65%;"></div>
                            </div>
                            <div class="progress-percentage">65%</div>
                        </div>
                        
                        <div class="modal-section">
                            <div class="modal-section-title">问题汇总</div>
                            <div class="safety-summary">
                                <div class="safety-summary-item safety-critical">
                                    <div class="safety-summary-count">2</div>
                                    <div class="safety-summary-label">严重问题</div>
                            </div>
                                <div class="safety-summary-item safety-warning">
                                    <div class="safety-summary-count">3</div>
                                    <div class="safety-summary-label">一般问题</div>
                        </div>
                                <div class="safety-summary-item safety-info">
                                    <div class="safety-summary-count">5</div>
                                    <div class="safety-summary-label">提示信息</div>
                                        </div>
                                    </div>
                                </div>
                                
                        <div class="modal-section">
                            <div class="modal-section-title">诊断合理性评估</div>
                            <div class="safety-check-list">
                                <div class="safety-check-item warning">
                                    <div class="safety-check-content">
                                        <div class="safety-check-icon">⚠️</div>
                                        <div class="safety-check-text">
                                            <div class="safety-check-title">诊断与症状匹配度不足</div>
                                            <div class="safety-check-suggestion">建议: 补充更多症状描述或调整诊断</div>
                                        </div>
                                    </div>
                                    <div class="safety-check-actions">
                                            <button class="btn btn-sm btn-default">采纳</button>
                                        <button class="btn btn-sm btn-default">拒绝</button>
                                        <button class="btn btn-sm btn-default">查看详情</button>
                            </div>
                        </div>
                        
                                <div class="safety-check-item info">
                                    <div class="safety-check-content">
                                        <div class="safety-check-icon">ℹ️</div>
                                        <div class="safety-check-text">
                                            <div class="safety-check-title">诊断依据可进一步完善</div>
                                            <div class="safety-check-suggestion">建议: 增加相关检查结果支持诊断</div>
                                        </div>
                                    </div>
                                    <div class="safety-check-actions">
                                            <button class="btn btn-sm btn-default">采纳</button>
                                        <button class="btn btn-sm btn-default">拒绝</button>
                                        <button class="btn btn-sm btn-default">查看详情</button>
                                        </div>
                                    </div>
                                    </div>
                                </div>
                                
                        <div class="modal-section">
                            <div class="modal-section-title">处方用药合理性评估</div>
                            <div class="safety-check-list">
                                <div class="safety-check-item critical">
                                    <div class="safety-check-content">
                                        <div class="safety-check-icon">❗</div>
                                        <div class="safety-check-text">
                                            <div class="safety-check-title">药物相互作用风险</div>
                                            <div class="safety-check-suggestion">药品A与药品B存在潜在相互作用</div>
                                            <div class="safety-check-suggestion">建议: 调整用药方案或密切监测</div>
                                        </div>
                                    </div>
                                    <div class="safety-check-actions">
                                            <button class="btn btn-sm btn-default">采纳</button>
                                        <button class="btn btn-sm btn-default">拒绝</button>
                                        <button class="btn btn-sm btn-default">查看详情</button>
                                        </div>
                                    </div>
                                
                                <div class="safety-check-item warning">
                                    <div class="safety-check-content">
                                        <div class="safety-check-icon">⚠️</div>
                                        <div class="safety-check-text">
                                            <div class="safety-check-title">用药剂量需调整</div>
                                            <div class="safety-check-suggestion">药品C的剂量超出推荐范围</div>
                                            <div class="safety-check-suggestion">建议: 降低剂量至xx-xx范围</div>
                                    </div>
                                </div>
                                    <div class="safety-check-actions">
                                        <button class="btn btn-sm btn-default">采纳</button>
                                        <button class="btn btn-sm btn-default">拒绝</button>
                                        <button class="btn btn-sm btn-default">查看详情</button>
                            </div>
                        </div>
                                        </div>
                                        </div>
                        
                        <div class="modal-section">
                            <div class="modal-section-title">患者风险评估</div>
                            <div class="safety-check-list">
                                <div class="safety-check-item info">
                                    <div class="safety-check-content">
                                        <div class="safety-check-icon">ℹ️</div>
                                        <div class="safety-check-text">
                                            <div class="safety-check-title">患者有特殊人群用药安全提示</div>
                                            <div class="safety-check-suggestion">老年患者，建议调整用药</div>
                                    </div>
                                    </div>
                                    <div class="safety-check-actions">
                                        <button class="btn btn-sm btn-default">采纳</button>
                                        <button class="btn btn-sm btn-default">拒绝</button>
                                        <button class="btn btn-sm btn-default">查看详情</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-primary" id="adoptAllSuggestionsBtn">采纳全部建议</button>
                        <button class="btn btn-default" id="finishCheckBtn">拒绝全部建议</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 全局下拉框 - 不受父容器限制 -->
    <div id="patientDropdown" style="position: fixed; width: 220px; max-height: 200px; overflow-y: auto; background: white; border: 1px solid var(--border-normal); border-radius: 2px; display: none; z-index: 9999; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);">
        <div class="dropdown-item" style="padding: 8px 12px; cursor: pointer; background-color: var(--bg-primary); transition: background-color 0.2s ease;">张三</div>
        <div class="dropdown-item" style="padding: 8px 12px; cursor: pointer; background-color: var(--bg-primary); transition: background-color 0.2s ease;">张小明</div>
        <div class="dropdown-item" style="padding: 8px 12px; cursor: pointer; background-color: var(--bg-primary); transition: background-color 0.2s ease;">张丽</div>
    </div>
    
    <!-- JavaScript 交互逻辑 -->
    <script>
        // 创建Vue应用
        document.addEventListener('DOMContentLoaded', function() {
            const { createApp, ref } = Vue;
            
            // 创建导航菜单Vue应用
            const navApp = createApp({
                setup() {
                    const activeIndex = ref('1'); // 默认选中"开始问诊"
                    
                    const handleSelect = (key, keyPath) => {
                        console.log(key, keyPath);
                        // 这里可以添加导航逻辑，如页面跳转等
                    };
                    
                    return {
                        activeIndex,
                        handleSelect
                    };
                }
            });
            
            // 使用Element Plus
            navApp.use(ElementPlus, {
                locale: ElementPlusLocaleZhCn
            });
            
            // 挂载Vue应用
            navApp.mount('#app-nav');
            
            // 初始化所有功能
            initCollapsibleSections();
            initImageUpload();
            initModals();
            initFeeCalculation();

            // 用户下拉：点击用户名切换显示，点击空白处关闭
            const userSection = document.getElementById('userSection');
            const userDropdown = document.getElementById('userDropdown');
            if (userSection && userDropdown) {
                userSection.addEventListener('click', function(e) {
                    e.stopPropagation();
                    const isOpen = userDropdown.style.display === 'block';
                    userDropdown.style.display = isOpen ? 'none' : 'block';
                });

                document.addEventListener('click', function() {
                    userDropdown.style.display = 'none';
                });
            }
            
            // 折叠面板功能
            function toggleSection(button, contentId) {
                const content = document.getElementById(contentId);
                const isExpanded = content.style.display === 'block';
                
                if (isExpanded) {
                    content.style.display = 'none';
                    button.classList.remove('expanded');
                } else {
                    content.style.display = 'block';
                    button.classList.add('expanded');
                }
            }
            
            // 全局函数，用于点击整个标题区域切换折叠面板
            window.toggleSectionHeader = function(header, contentId) {
                const content = document.getElementById(contentId);
                const toggleIconBtn = header.querySelector('.toggle-icon');
                const iconSvg = toggleIconBtn ? toggleIconBtn.querySelector('svg') : null;
                const isExpanded = content.style.display === 'block';

                if (isExpanded) {
                    content.style.display = 'none';
                    header.classList.remove('expanded');
                    if (toggleIconBtn) toggleIconBtn.classList.remove('expanded');
                    if (iconSvg) iconSvg.classList.remove('expanded');
                } else {
                    content.style.display = 'block';
                    header.classList.add('expanded');
                    if (toggleIconBtn) toggleIconBtn.classList.add('expanded');
                    if (iconSvg) iconSvg.classList.add('expanded');
                }
            };
            
            // 初始化折叠面板
            function initCollapsibleSections() {
                // 为按钮添加阻止事件冒泡的处理
                // 使用ID选择器获取元素并绑定事件
                const historyHeader = document.getElementById('historyHeader');
                const physicalExamHeader = document.getElementById('physicalExamHeader');
                const imageCaptureHeader = document.getElementById('imageCaptureHeader');
                
                if (historyHeader) {
                    historyHeader.addEventListener('click', function() {
                        toggleSectionHeader(this, 'historyContent');
                    });
                    const historyIcon = historyHeader.querySelector('.toggle-icon');
                    if (historyIcon) {
                        historyIcon.addEventListener('click', function(e) {
                            e.stopPropagation();
                            toggleSectionHeader(historyHeader, 'historyContent');
                        });
                    }
                }
                
                if (physicalExamHeader) {
                    physicalExamHeader.addEventListener('click', function() {
                        toggleSectionHeader(this, 'physicalExamContent');
                    });
                    const physicalIcon = physicalExamHeader.querySelector('.toggle-icon');
                    if (physicalIcon) {
                        physicalIcon.addEventListener('click', function(e) {
                            e.stopPropagation();
                            toggleSectionHeader(physicalExamHeader, 'physicalExamContent');
                        });
                    }
                }
                
                if (imageCaptureHeader) {
                    imageCaptureHeader.addEventListener('click', function() {
                        toggleSectionHeader(this, 'imageCaptureContent');
                    });
                    const imageIcon = imageCaptureHeader.querySelector('.toggle-icon');
                    if (imageIcon) {
                        imageIcon.addEventListener('click', function(e) {
                            e.stopPropagation();
                            toggleSectionHeader(imageCaptureHeader, 'imageCaptureContent');
                        });
                    }
                }
            }
            
            // 图片上传功能
            function initImageUpload() {
            const uploadImageBox = document.getElementById('uploadImageBox');
            const imageUpload = document.getElementById('imageUpload');
            const imagePreview1 = document.getElementById('imagePreview1');
                const imagePreview2 = document.getElementById('imagePreview2');
                const imagePreview3 = document.getElementById('imagePreview3');
            
            if (uploadImageBox && imageUpload) {
                uploadImageBox.addEventListener('click', function() {
                    imageUpload.click();
                });
                
                imageUpload.addEventListener('change', function(e) {
                    if (e.target.files && e.target.files[0]) {
                        const reader = new FileReader();
                            
                            // 查找第一个未使用的预览区域
                            let targetPreview;
                            if (imagePreview1.style.display === 'none' || imagePreview1.style.display === '') {
                                targetPreview = imagePreview1;
                            } else if (imagePreview2.style.display === 'none' || imagePreview2.style.display === '') {
                                targetPreview = imagePreview2;
                            } else if (imagePreview3.style.display === 'none' || imagePreview3.style.display === '') {
                                targetPreview = imagePreview3;
                            } else {
                                // 如果所有预览区域都已使用，则使用第一个
                                targetPreview = imagePreview1;
                            }
                        
                        reader.onload = function(e) {
                                const img = targetPreview.querySelector('img');
                            img.src = e.target.result;
                                targetPreview.style.display = 'block';
                        };
                        
                        reader.readAsDataURL(e.target.files[0]);
                    }
                });
                }
            }
            
            // 删除图片功能
            window.deleteImage = function(previewId) {
                const preview = document.getElementById(previewId);
                if (preview) {
                    preview.style.display = 'none';
                    const img = preview.querySelector('img');
                    img.src = '#';
                    
                    // 清除文件输入
                    const imageUpload = document.getElementById('imageUpload');
                    if (imageUpload) {
                        imageUpload.value = '';
                    }
                }
            };
            
            // 初始化弹窗
            function initModals() {
            // AI辅助诊断弹窗
            const aiDiagnosisBtn = document.getElementById('aiDiagnosisBtn');
            const aiDiagnosisModal = document.getElementById('aiDiagnosisModal');
            const closeAiDiagnosisModal = document.getElementById('closeAiDiagnosisModal');
            const cancelAiDiagnosisBtn = document.getElementById('cancelAiDiagnosisBtn');
            
            if (aiDiagnosisBtn && aiDiagnosisModal) {
                aiDiagnosisBtn.addEventListener('click', function() {
                        // 更新患者信息
                        updatePatientInfoInModal();
                    aiDiagnosisModal.classList.add('active');
                });
                
                if (closeAiDiagnosisModal) {
                    closeAiDiagnosisModal.addEventListener('click', function() {
                        aiDiagnosisModal.classList.remove('active');
                    });
                }
                
                if (cancelAiDiagnosisBtn) {
                    cancelAiDiagnosisBtn.addEventListener('click', function() {
                        aiDiagnosisModal.classList.remove('active');
                    });
                }
            }
            
            // AI诊断结果采纳功能
            const adoptDiagnosisBtn = document.getElementById('adoptDiagnosisBtn');
            const adoptPrescriptionBtn = document.getElementById('adoptPrescriptionBtn');
            const adoptAdviceBtn = document.getElementById('adoptAdviceBtn');
            const adoptAllBtn = document.getElementById('adoptAllBtn');
            const diagnosis = document.getElementById('diagnosis');
            const diagnosisBasis = document.getElementById('diagnosisBasis');
            const medicalAdvice = document.getElementById('medicalAdvice');
            
            if (adoptDiagnosisBtn && diagnosis) {
                adoptDiagnosisBtn.addEventListener('click', function() {
                    diagnosis.value = "上呼吸道感染";
                    aiDiagnosisModal.classList.remove('active');
                });
            }
            
            if (adoptPrescriptionBtn) {
                adoptPrescriptionBtn.addEventListener('click', function() {
                        // 添加药品到表格
                        addPrescriptionToTable();
                    aiDiagnosisModal.classList.remove('active');
                });
            }
            
            if (adoptAdviceBtn && medicalAdvice) {
                adoptAdviceBtn.addEventListener('click', function() {
                    medicalAdvice.value = "1. 多饮水，注意休息\n2. 避免辛辣刺激食物\n3. 症状无缓解，3天后复诊";
                    aiDiagnosisModal.classList.remove('active');
                });
            }
            
            if (adoptAllBtn && diagnosis && diagnosisBasis && medicalAdvice) {
                adoptAllBtn.addEventListener('click', function() {
                    diagnosis.value = "上呼吸道感染";
                    diagnosisBasis.value = "症状分析: 患者主诉发热、咳嗽3天，体温38.5℃，伴有咽痛、流涕等症状\n体征分析: 咽部充血，双侧扁桃体Ⅰ度肿大，未见明显分泌物\n辅助检查: 血常规示白细胞计数轻度升高，以中性粒细胞为主";
                    medicalAdvice.value = "1. 多饮水，注意休息\n2. 避免辛辣刺激食物\n3. 症状无缓解，3天后复诊";
                    
                    // 添加药品到表格
                        addPrescriptionToTable();
                        
                        aiDiagnosisModal.classList.remove('active');
                    });
                }
                
                // 医疗安全检查弹窗
                const checkDiagnosisBtn = document.getElementById('checkDiagnosisBtn');
                const safetyCheckModal = document.getElementById('safetyCheckModal');
                const closeSafetyCheckModal = document.getElementById('closeSafetyCheckModal');
                const finishCheckBtn = document.getElementById('finishCheckBtn');
                
                if (checkDiagnosisBtn && safetyCheckModal) {
                    checkDiagnosisBtn.addEventListener('click', function() {
                        safetyCheckModal.classList.add('active');
                    });
                    
                    if (closeSafetyCheckModal) {
                        closeSafetyCheckModal.addEventListener('click', function() {
                            safetyCheckModal.classList.remove('active');
                        });
                    }
                    
                    if (finishCheckBtn) {
                        finishCheckBtn.addEventListener('click', function() {
                            safetyCheckModal.classList.remove('active');
                        });
                    }
                }
            }
            
            // 更新患者信息到弹窗
            function updatePatientInfoInModal() {
                const patientName = document.getElementById('patientName').value || '张三';
                const gender = document.getElementById('gender').value === 'male' ? '男' : 
                               document.getElementById('gender').value === 'female' ? '女' : '';
                const age = document.getElementById('age').value || '35';
                
                const patientInfoInModal = document.getElementById('patientInfoInModal');
                if (patientInfoInModal) {
                    patientInfoInModal.textContent = `${patientName}（${gender}，${age}岁）`;
                }
            }
            
            // 添加处方到表格
            function addPrescriptionToTable() {
                    const medicineTableBody = document.getElementById('medicineTableBody');
                    if (medicineTableBody) {
                        medicineTableBody.innerHTML = `
                            <tr>
                                <td>布洛芬</td>
                                <td>0.2g/片</td>
                                <td>口服</td>
                                <td>1片</td>
                                <td>tid</td>
                            <td>3天</td>
                                <td>0.28</td>
                            <td>9</td>
                                <td>
                                <button class="btn-sm btn-default" onclick="deleteMedicine(this)">删除</button>
                                </td>
                            </tr>
                            <tr>
                                <td>感冒灵</td>
                                <td>10g/袋</td>
                                <td>冲服</td>
                                <td>1袋</td>
                                <td>tid</td>
                            <td>3天</td>
                                <td>2.50</td>
                            <td>9</td>
                                <td>
                                <button class="btn-sm btn-default" onclick="deleteMedicine(this)">删除</button>
                                </td>
                            </tr>
                            <tr>
                                <td>板蓝根</td>
                                <td>10g/袋</td>
                                <td>冲服</td>
                                <td>1袋</td>
                                <td>tid</td>
                            <td>3天</td>
                                <td>3.50</td>
                            <td>9</td>
                                <td>
                                <button class="btn-sm btn-default" onclick="deleteMedicine(this)">删除</button>
                                </td>
                            </tr>
                        `;
                        
                        // 更新药品费用
                        updateMedicineFee();
                    }
            }
            
            // 删除药品功能
            window.deleteMedicine = function(btn) {
                const row = btn.closest('tr');
                row.remove();
                
                // 检查是否还有药品行
                const medicineTableBody = document.getElementById('medicineTableBody');
                if (medicineTableBody && medicineTableBody.querySelectorAll('tr').length === 0) {
                    medicineTableBody.innerHTML = '<tr><td colspan="9" class="empty-table-message">暂无药品，请点击"添加药品"按钮</td></tr>';
                }
                
                // 更新药品费用
                updateMedicineFee();
            };
            
            // 初始化费用计算
            function initFeeCalculation() {
            // 添加药品按钮功能
            const addMedicineBtn = document.getElementById('addMedicineBtn');
            if (addMedicineBtn) {
                addMedicineBtn.addEventListener('click', function() {
                    // 以iframe方式在本页打开20-选择药品弹窗.html
                    let frameWrap = document.getElementById('pickerFrameWrap');
                    if (!frameWrap) {
                        frameWrap = document.createElement('div');
                        frameWrap.id = 'pickerFrameWrap';
                        frameWrap.className = 'modal-overlay active';
                        frameWrap.innerHTML = `<div class="modal" style="width:100vw;height:100vh;max-width:100vw;max-height:100vh;border-radius:0;box-shadow:none;padding:0;">
                            <div style="flex:1;height:100%;display:flex;flex-direction:column;">
                                <iframe id="pickerIframe" src="20-选择药品弹窗.html" style="border:0; width:100%; height:100%;"></iframe>
                            </div>
                        </div>`;
                        document.body.appendChild(frameWrap);
                        // 将个人药品库发送给子页面
                        const iframe = document.getElementById('pickerIframe');
                        iframe.addEventListener('load', function(){
                            const payload = collectPersonalDrugsForPicker();
                            iframe.contentWindow && iframe.contentWindow.postMessage({ type:'PERSONAL_DRUGS_INIT', payload }, '*');
                        });
                    }
                });
            }

            function collectPersonalDrugsForPicker(){
                // 从个人药品数据源抽取; 这里以处方可用字段为准，若项目内有全局药品数据，可在此替换
                // 简化：若 15页个人药品数据不可直接用，这里可临时提供空数组或从后端拉取
                if (Array.isArray(window.__PERSONAL_DRUGS__)) return window.__PERSONAL_DRUGS__;
                return [];
            }
                
                // 监听问诊费用变化
                const consultationFee = document.getElementById('consultationFee');
                if (consultationFee) {
                    consultationFee.addEventListener('input', updateMedicineFee);
                }
                
                // 保存和重置按钮
                const saveBtn = document.getElementById('saveBtn');
                const resetBtn = document.getElementById('resetBtn');
                
                if (saveBtn) {
                    saveBtn.addEventListener('click', function() {
                        // 验证必填字段
                        if (validateRequiredFields()) {
                            alert('病历保存成功！');
                        } else {
                            alert('请填写所有必填字段（标记有*）');
                        }
                    });
                }
                
                if (resetBtn) {
                    resetBtn.addEventListener('click', function() {
                        if (confirm('确定要重置所有内容吗？')) {
                            resetAllFields();
                        }
                    });
                }
            }
            
            // 更新药品费用
            function updateMedicineFee() {
                const medicineTableBody = document.getElementById('medicineTableBody');
                const medicineFee = document.getElementById('medicineFee');
                const consultationFee = document.getElementById('consultationFee');
                const totalFeeDisplay = document.getElementById('totalFeeDisplay');
                
                if (medicineTableBody && medicineFee) {
                    // 计算药品总费用
                    let total = 0;
                    const rows = medicineTableBody.querySelectorAll('tr');
                    rows.forEach(row => {
                        const cells = row.querySelectorAll('td');
                        if (cells.length >= 8 && !row.querySelector('.empty-table-message')) {
                            const price = parseFloat(cells[6].textContent) || 0;
                            const quantity = parseInt(cells[7].textContent) || 0;
                            total += price * quantity;
                        }
                    });
                    
                    medicineFee.value = total.toFixed(2);
                    
                    // 更新总费用显示
                    const consultation = parseFloat(consultationFee.value) || 0;
                    const totalFee = total + consultation;
                    
                    // 更新底部栏中的总费用显示
                    if (totalFeeDisplay) {
                        totalFeeDisplay.textContent = totalFee.toFixed(2);
                    }
                }
            }

            // 接收选择药品并写入处方表
            function addPickedDrugsToTable(picked) {
                const medicineTableBody = document.getElementById('medicineTableBody');
                if (!medicineTableBody) return;
                const placeholder = medicineTableBody.querySelector('td.empty-table-message');
                if (placeholder) medicineTableBody.innerHTML = '';
                (picked || []).forEach(d => {
                    const row = document.createElement('tr');
                    const price = (d.price ? String(d.price) : '0.00');
                    row.innerHTML = `
                        <td contenteditable="true">${d.name || ''}</td>
                        <td contenteditable="true">${d.spec || ''}</td>
                        <td contenteditable="true">${d.usage || ''}</td>
                        <td contenteditable="true">${d.dosage || ''}</td>
                        <td contenteditable="true">${d.frequency || ''}</td>
                        <td contenteditable="true">3</td>
                        <td contenteditable="true">${price}</td>
                        <td contenteditable="true">0</td>
                        <td><button class="btn-sm btn-default" onclick="deleteMedicine(this)">删除</button></td>`;
                    medicineTableBody.appendChild(row);
                    row.querySelectorAll('[contenteditable="true"]').forEach(cell => cell.addEventListener('input', updateMedicineFee));
                });
                updateMedicineFee();
            }

            // 弹窗回调与消息监听
            window.onDrugsPicked = function(list){ try { addPickedDrugsToTable(list); } catch(e){ console.warn(e); } };
            window.addEventListener('message', function(e){
                const d=e&&e.data;
                if(d&&d.type==='DRUGS_PICKED'){ addPickedDrugsToTable(d.payload||[]); }
                if(d&&d.type==='PICKER_CLOSE'){ const wrap=document.getElementById('pickerFrameWrap'); if(wrap) document.body.removeChild(wrap); }
            });
            
            // 验证必填字段
            function validateRequiredFields() {
                // 患者基本信息
                const patientName = document.getElementById('patientName').value;
                const gender = document.getElementById('gender').value;
                const age = document.getElementById('age').value;
                const phone = document.getElementById('phone').value;
                
                // 主诉
                const chiefComplaint = document.getElementById('chiefComplaint').value;
                
                // 诊断结果
                const diagnosis = document.getElementById('diagnosis').value;
                
                // 处方药品
                const hasMedicine = !document.querySelector('#medicineTableBody .empty-table-message');
                
                // 问诊费用
                const consultationFee = document.getElementById('consultationFee').value;
                
                return patientName && gender && age && phone && chiefComplaint && diagnosis && hasMedicine && consultationFee;
            }
            
            // 重置所有字段
            function resetAllFields() {
                // 重置患者信息
                document.getElementById('patientName').value = '';
                document.getElementById('gender').value = '';
                document.getElementById('age').value = '';
                document.getElementById('idCard').value = '';
                document.getElementById('phone').value = '';
                
                // 重置主诉
                document.getElementById('chiefComplaint').value = '';
                
                // 重置病史
                document.getElementById('presentIllness').value = '';
                document.getElementById('allergyHistory').value = '';
                document.getElementById('pastHistory').value = '';
                document.getElementById('personalHistory').value = '';
                document.getElementById('familyHistory').value = '';
                
                // 重置体格检查
                document.getElementById('temperature').value = '';
                document.getElementById('pulse').value = '';
                document.getElementById('respiration').value = '';
                document.getElementById('bloodPressure').value = '';
                document.getElementById('generalCondition').value = '';
                document.getElementById('specialExam').value = '';
                
                // 重置图像采集
                document.getElementById('imageDescription').value = '';
                
                // 重置图片预览
                document.getElementById('imagePreview1').style.display = 'none';
                document.getElementById('imagePreview2').style.display = 'none';
                document.getElementById('imagePreview3').style.display = 'none';
                
                // 重置诊断
                document.getElementById('diagnosis').value = '';
                document.getElementById('diagnosisBasis').value = '';
                
                // 重置处方
                        const medicineTableBody = document.getElementById('medicineTableBody');
                        if (medicineTableBody) {
                    medicineTableBody.innerHTML = '<tr><td colspan="9" class="empty-table-message">暂无药品，请点击"添加药品"按钮</td></tr>';
                }
                
                // 重置医嘱
                document.getElementById('medicalAdvice').value = '';
                
                // 重置费用
                document.getElementById('consultationFee').value = '';
                document.getElementById('medicineFee').value = '0';
                document.getElementById('totalFeeDisplay').textContent = '0';
            }
            
            // 患者姓名搜索下拉 - 使用固定定位的全局下拉框
            const patientName = document.getElementById('patientName');
            const patientDropdown = document.getElementById('patientDropdown');
            
            if (patientName && patientDropdown) {
                // 显示下拉框并定位到输入框下方
                function showDropdown() {
                    // 获取输入框的位置和尺寸
                    const rect = patientName.getBoundingClientRect();
                    
                    // 设置下拉框的位置，使其位于输入框正下方
                    patientDropdown.style.top = (rect.bottom + window.scrollY) + 'px';
                    patientDropdown.style.left = (rect.left + window.scrollX) + 'px';
                    patientDropdown.style.width = rect.width + 'px';
                    patientDropdown.style.display = 'block';
                }
                
                // 输入框获得焦点时显示下拉框
                patientName.addEventListener('focus', showDropdown);
                
                // 输入框点击时显示下拉框
                patientName.addEventListener('click', showDropdown);
                
                // 处理窗口滚动和调整大小时重新定位下拉框
                window.addEventListener('scroll', function() {
                    if (patientDropdown.style.display === 'block') {
                        showDropdown();
                    }
                });
                
                window.addEventListener('resize', function() {
                    if (patientDropdown.style.display === 'block') {
                        showDropdown();
                    }
                });
                
                // 使用全局点击事件处理下拉框的隐藏
                document.addEventListener('click', function(event) {
                    // 如果点击的不是患者姓名输入框和下拉框内的元素，则隐藏下拉框
                    if (!patientName.contains(event.target) && !patientDropdown.contains(event.target)) {
                        patientDropdown.style.display = 'none';
                    }
                });
                
                // 添加鼠标悬停效果
                const dropdownItems = patientDropdown.querySelectorAll('.dropdown-item');
                dropdownItems.forEach(item => {
                    item.addEventListener('mouseover', function() {
                        this.style.backgroundColor = 'var(--bg-secondary)';
                    });
                    
                    item.addEventListener('mouseout', function() {
                        this.style.backgroundColor = 'var(--bg-primary)';
                    });
                    
                    item.addEventListener('click', function() {
                        patientName.value = this.textContent;
                        patientDropdown.style.display = 'none';
                    });
                });
                
                // 处理输入框内容变化时的过滤功能
                patientName.addEventListener('input', function() {
                    const inputValue = this.value.toLowerCase();
                    
                    // 过滤下拉项
                    dropdownItems.forEach(item => {
                        const itemText = item.textContent.toLowerCase();
                        if (itemText.includes(inputValue)) {
                            item.style.display = 'block';
                        } else {
                            item.style.display = 'none';
                        }
                    });
                    
                    // 如果有输入内容，显示下拉框
                    if (this.value) {
                        showDropdown();
                    }
                });
            }
        });
    </script>
</body>
</html>

